package core

import (
	"gorm.io/gorm"
	"lib/logger"
	"sync"
)

var once sync.Once
var context ApplicationContext

type ApplicationContext struct {
	DBInstance  *gorm.DB
	Initialized bool
}

func initialization(db *gorm.DB) {
	once.Do(func() {
		context = ApplicationContext{
			DBInstance:  db,
			Initialized: true,
		}
	})
}

func Instance() ApplicationContext {
	if !context.Initialized {
		logger.Error("ApplicationContext was not initialized yet!")
	}
	return context
}
